#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: title01去除多余空格.py 
@version:
@time: 2023/05/29

https://dream.blog.csdn.net/article/details/128995183

Life is painting a  picture, not doing 'a  sum'.
8 15,20 26,43 45


Life is painting a picture, not doing 'a  sum'.
[8, 15][19, 25][42, 44]

"""
from typing import List

input_string = input().strip()
input_strings = input().split(",")

words_list = []
coordinates_list = []
letters_count = 0
is_in_brackets = False
index_word = 0
index_coordinate = 0
is_over = False
temp_string = ""

while not is_over:
    coordinate_pair = input_strings[index_coordinate].split(" ")
    start_index = int(coordinate_pair[0])
    end_index = int(coordinate_pair[1])
    if index_coordinate < len(input_strings) - 1:
        index_coordinate += 1

    new_start_index = 0
    new_end_index = 0

    for j in range(index_word, len(input_string)):

        c = input_string[j]
        if c == " ":
            if is_in_brackets:
                temp_string += c
                continue
            if temp_string != "":
                letters_count += len(temp_string)
                words_list.append(temp_string)
                temp_string = ""
        elif c == "'":
            is_in_brackets = not is_in_brackets
            temp_string += c
        else:
            temp_string += c

        # 如果j是输入字符的最后一个index，添加未处理完的temp_string,is_over为True
        if j == len(input_string) - 1:
            if temp_string != "":
                words_list.append(temp_string)
            is_over = True

        # 如果j等于start_index
        if j == start_index:
            # new_start_index 等于字符的
            new_start_index = (
                    len(words_list)  # len(words_list)其实就是中间的空格数
                    + letters_count  # 这个是字符的数量
                    + (len(temp_string) - 1 if is_in_brackets else 0) # 如果有
            )

            new_end_index = end_index - start_index + new_start_index
            coordinates_list.append([new_start_index, new_end_index])
            index_word = j + 1
            break

result_string = " ".join(words_list)
print(result_string)
result_coordinates = list(map(str, coordinates_list))
result_coordinates = ''.join(result_coordinates)

print(result_coordinates)
